<template>
    <div class="logos">
        <div class="j-row" @click="onlogo">
            <img src="@/assets/logo.png" class="log-img" />
            <div class="alpha">Alpha</div>
        </div>
        <div style="flex:1"></div>

        <v-menu transition="slide-y-reverse-transition" origin="start">
            <template v-slot:activator="{ props }">
                <span class="iconfont icon-liulanqi2-mianxing lang" v-bind="props"></span>
            </template>
            <v-list>
                <v-list-item v-for="item in langs">
                    <v-list-item-title class="d-flex align-center fline" @click="() => toggleLang(item)">
                        <div class="i-txt c-title-4">{{ item.name }}</div>
                    </v-list-item-title>
                </v-list-item>
            </v-list>
        </v-menu>
    </div>
</template>

<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { useTheme } from "vuetify";
import { useAccount } from "@/stores/account";
import { computed, ref } from "vue";
import { useLayout } from "@/stores/layout";
import { TOGGLE_PAUSE, Bus } from "@/connetion/Bus";
import { useRouter } from "vue-router";
// import { post } from "@/comm/request";
// import { URL_LOGIN_OUT } from "@/comm/api";
import { useUser } from "@/stores/user";
import { maskEmail } from "@/comm/tooler";
import JSuggest from "@/components/j-suggest/index.vue";
import { useCore } from "@/hooks/useCore";
import JBookMark from "@/components/j-bookmark/index.vue";
import BookMarkImg from "@/components/j-svg/bookMarkImg.vue";
import UrgentNotice from "@/components/j-svg/urgentNotice.vue";
import JEnergy from "@/components/j-energy/index.vue"
import JNumber from "@/components/j-number/index.vue"
import YNavS from "@/components/y-nvas/index.vue"
const user = useUser();
const layout = useLayout();

const account = useAccount();
const theme = useTheme();

const router = useRouter();
const core = useCore();

const langs = ref([
    {
        name: "English",
        value: "en"
    },
    {
        name: "Español",
        value: "es"
    },
    {
        name: "Русский",
        value: "pyc"
    },
    {
        name: "한국어",
        value: "ko"
    },
    {
        name: "日本語",
        value: "jp"
    },
    {
        name: "繁体中文",
        value: "zh"
    },
]);

const userName = computed(() => {
    if (user.info && user.info.userName) {
        return maskEmail(user.info.userName);
    }
    return "";
});

const onTest = () => {
    console.log(user.info);
};
const onUser = () => {
    router.push("/user");
};
const onSetting = () => {
    router.push("/setting");
};

const onTry = () => {
    router.push("/plan");
};

const register = () => {
    window.open('/reward', '_self');
    // account.popRegister = true;
}

const onNav = () => {
    layout.toggleNavOpen();
};

const onNews = () => {
    layout.toggleNewsOpen();
};

const onlogo = () => {
    // Bus.emit(TOGGLE_PAUSE);
    // let obj = ["/entity", "/coin", "/token", "/address"].find(i => location.href.includes(i));
    // if (obj) {
    //     location.replace("/home");
    //     return;
    // }
    // router.push("/home");
    // if (location.pathname === "/") {
    //     location.reload();
    // } else {
    //     core.goHome();
    // }

    location.href = "/"
};

const onQuit = () => {
    user.quit();
};

function toggleTheme() {
    theme.global.name.value = theme.global.current.value.dark ? "light" : "dark";
    if (theme.global.name.value) {
        document.documentElement.style.setProperty("--main", "#fcc235");
        document.documentElement.style.setProperty("--sub", "#B1B6C6");
    } else {
        document.documentElement.style.setProperty("--main", "#00ff00");
        document.documentElement.style.setProperty("--sub", "#006600");
    }
}

const onTheme = () => {
    layout.toggleIsDark();
    console.log("onTheme", darkCls);
};

const darkCls = computed(() => {
    if (layout.isDark) {
        return "icon-sunny-sharp";
    }
    return "icon-moon_stars_fill";
});

const { t, locale } = useI18n();
const toggleLang = (ent: { name: string; value: string }) => {
    // console.log("yzt");
    if (ent.value !== locale.value) {
        localStorage.setItem("language", ent.value);
        locale.value = ent.value;
        window.location.reload();
    }
    // locale.value = locale.value === "zh" ? "en" : "zh";
    // if (ent.value === locale.value) {
    // }
};

const showLogin = () => {
    account.changePopLogin(true);
    // account.changePopShare(true);
};

const isDark = ref(false);

const onLang = () => {
    console.log("onLang");
};

const onZh = () => {
    console.log("onZh");
};
</script>

<style lang="less" scoped>
.logos{
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.j-row {
    display: flex;
    align-items: center;
    height: 100%;
    // backdrop-filter: blur(1px);
    // background-color: rgba(25, 25, 32, 0.8);
    margin-left: 20px;
}

// .header {
//     width: 30px;
//     height: 30px;
//     background: #d5d7da;
//     border-radius: 50%;
// }

.space {
    flex: 1;
}

.a-btn {
    width: 30px;
    height: 30px;
    background: #2b3139;
    border-radius: 6px;
    margin: 0 35px;
    margin-left: 18px;
    transition: all 0.3s;

    &:hover {
        background: #343a45;
    }

    .icon-more {
        font-size: 12px;
        color: var(--main);

        &.open {
            transform: scaleX(-1);
        }
    }
}

.icon-yonghutouxiang {
    font-size: 30px;
}



.log-img {
    width: 138px;
    height: 21px;
    object-fit: contain;
    margin-right: 30px;
}

.j-btn {
    padding: 0 8px;
    height: 28px;
    // background: linear-gradient(90deg, #FDEA58 0%, #FA2C29 100%);
    font-family: var(--font-family);
    font-weight: 700;

    background: var(--main);
    margin-right: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    color: #000;

    .d-t1 {
        font-size: 14px;
    }

    .d-t2 {
        font-size: 12px;
        // margin-top: -4px;
    }
}

.l-btn {
    // width: 50px;
    padding: 0 10px;
    height: 28px;
    background: #191920;
    border-radius: 4px;
    border: 1px solid #fcc235;
    font-size: 12px;
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    // margin-right: 20px;
    transition: all 300ms;
    white-space: nowrap;

    &:hover {
        background: rgba(255, 255, 255, 0.1);
    }
}

.start-btn {
    padding: 0 10px;
    width: fit-content;
    height: 28px;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 12px;
    background: var(--main);
    // margin-right: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    color: #000;
    // margin-right: 20px;
}

:deep(.v-input) {
    flex: unset;
}

:deep(.v-input__control) {
    margin: 0;
    padding: 0;
}

:deep(.v-input__details) {
    display: none;
}

:deep(.v-list-item) {
    padding: 0 !important;
    margin: 0 !important;

    &:last-child {
        .fline {
            // border-bottom: none;
        }
    }
}

:deep(.v-list) {
    background: var(--card) !important;
    user-select: none;
}

.fline {
    // border-bottom: 1px solid var(--border);
    padding: 15px;
    height: 50px;
}

.v-list {
    position: relative;
    top: 10px;
    padding: 0;
}

.sub-txt {
    color: var(--sub);
    font-size: 14px;
}

.lang {
    color: #ffffff;
    padding-top: 2px;
    font-size: 19px;
    margin-right: 20px;

    &:hover {
        color: var(--main);
    }
}

.color {
    font-size: 20px;
    margin-right: 25px;
    color: #ffffff;

    &:hover {
        color: var(--main);
    }
}

.energy {
    border-radius: 11px;
    background-color: rgba(255, 255, 255, 0.12);
    // margin-right: 20px;
}

.energy-img {
    width: 18px;
    height: 18px;
    object-fit: contain;
    -webkit-user-drag: none;
}

.energy-num {
    color: #ffffff;
    font-size: 13px;
    margin-left: 4px;
    margin-right: 10px;
    // margin-block: px;
}

.role-ico {
    font-size: 16px;
    color: #fff;
    margin-right: 8px;
}

.i-txt {
    // font-size: 16px;
    color: #fff;
}

.l-item {
    transition: all 0.3s;

    :hover {
        background: #2a3139;
    }
}

.test-ico {
    width: 30px;
    height: 30px;
    transform: rotate(135deg);
}

.header-pro {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.ico-menu {
    color: var(--main);
}

.souchang {
    // margin-right: 20px;
    // margin-left: 20px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;

    &:hover {
        :deep(#sc) {
            fill: var(--main);
        }
    }

    // background-color: red;
}

.j-exp_ {
    margin-right: 20px;
    // width: 18px;
    height: 18px;
}

#jingbao {
    fill: white;

    &:hover {
        fill: var(--main);
    }
}

.p-btns {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 20px;
    margin-right: 20px;
}

.j-exp {
    width: 20px;
    height: 20px;
    background: url("@/assets/arow-n.png") no-repeat center;
    background-size: contain;
    margin-right: 30px;
    transform: rotate(180deg);

    &.open {
        transform: rotate(0deg);
    }

    &:hover {
        background-image: url("@/assets/arow-c.png");
    }
}

.alpha {
    // background: url("@/assets/alpha.svg") no-repeat center;
    // background-size: contain;
    width: fit-content;
    padding: 1px 6px 2px 6px;
    position: absolute;
    left: 154px;
    top: 12px;
    z-index: 1;
    color: #171a1f;
    background: var(--main);
    border-radius: 12px;
    font-size: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    transform: scale(0.8);
}

.sug-box {
    margin-left: 30px;
}
</style>
